package com.tbm.console.proj.json;

import com.tbm.console.common.constant.InsUpdDelFlagConstant;
import com.tbm.console.base.controller.BaseController;
import com.tbm.console.proj.entity.TestEntity;
import com.tbm.console.proj.service.TestService;
import com.tbm.console.util.DateUtil;
import com.tbm.console.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

//说明 字符串：Test，作为替换字符串 LOWERTest

@RestController
public class TestJson extends BaseController{

    @Autowired
    private TestService testService;

    /**
     * 显示list
     * @param page
     * @param size
     * @return
     */
    @RequestMapping(value = "/test-list/{page}/{size}")
    public Map<String,Object> testList(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
        PageData pageData = this.getPageData();
        pageData.put("deleteFlag", "N");
        long count = testService.count(pageData);
        List<TestEntity> tests = testService.findAll(pageData,page-1,size);
        pageData.put("total",count);
        pageData.put("rows", tests);
        return pageData;
    }

    /**
     * 常量增删改
     * @return
     */
    @RequestMapping(value = "/test-ins-upd-del")
    public Object logCreateUpdate(){
        PageData pageData = this.getPageData();
        Integer id = -1;
        if(null != pageData.get("id")&&!"".equals(pageData.get("id").toString())){
            id = Integer.valueOf(pageData.get("id").toString());
        }
        TestEntity test = testService.findById(id);

        //------------------------------------------------------- 新增修改操作 ----------------------------------------------------------------------//

        if(-1==id){
            test.setCreateTime(DateUtil.getTime());
			test.setDeleteFlag(InsUpdDelFlagConstant.LOCALLOGDELETEFLAG);
        }else{
            test.setUpdateTime(DateUtil.getTime());
        }

        //字段信息维护
        if(null!=pageData.get("***")&&!"".equals(pageData.get("***").toString())){
			//目前只能手动添加，这里添加所需要增加和修改的字段
            //test.set***(pageData.get("***").toString());
        }
        
        //------------------------------------------------------- 删除操作 ---------------------------------------------------------------------------//
        if(null!=pageData.get("flag")&&"Y".equals(pageData.get("flag").toString())){
            test.setDeleteFlag(pageData.get("flag").toString());
        }
        testService.save(test);
        return null;
    }   
}